package com.ruoyi.park.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.park.domain.ParkInfo;
import com.ruoyi.park.service.IParkInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.park.domain.ParkSpace;
import com.ruoyi.park.service.IParkSpaceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车位管理Controller
 * 
 * @author 博雅
 * @date 2023-12-11
 */
@RestController
@RequestMapping("/park/space")
public class ParkSpaceController extends BaseController
{
    @Autowired
    private IParkSpaceService parkSpaceService;
    @Autowired
    private IParkInfoService parkInfoService;

    /**
     * 查询车位管理列表
     */
    @PreAuthorize("@ss.hasPermi('park:space:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParkSpace parkSpace)
    {
        startPage();
        List<ParkSpace> list = parkSpaceService.selectParkSpaceList(parkSpace);
        return getDataTable(list);
    }

    @GetMapping("/parkList")
    public AjaxResult parkList()
    {
        List<ParkInfo> list = parkInfoService.selectParkInfoList(null);
        return success(list);
    }

    /**
     * 导出车位管理列表
     */
    @PreAuthorize("@ss.hasPermi('park:space:export')")
    @Log(title = "车位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkSpace parkSpace)
    {
        List<ParkSpace> list = parkSpaceService.selectParkSpaceList(parkSpace);
        ExcelUtil<ParkSpace> util = new ExcelUtil<ParkSpace>(ParkSpace.class);
        util.exportExcel(response, list, "车位管理数据");
    }

    /**
     * 获取车位管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('park:space:query')")
    @GetMapping(value = "/{spaceId}")
    public AjaxResult getInfo(@PathVariable("spaceId") Long spaceId)
    {
        return success(parkSpaceService.selectParkSpaceBySpaceId(spaceId));
    }

    /**
     * 新增车位管理
     */
    @PreAuthorize("@ss.hasPermi('park:space:add')")
    @Log(title = "车位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkSpace parkSpace)
    {
        parkSpace.setSpaceStatus("3");
        return toAjax(parkSpaceService.insertParkSpace(parkSpace));
    }

    /**
     * 修改车位管理
     */
    @PreAuthorize("@ss.hasPermi('park:space:edit')")
    @Log(title = "车位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkSpace parkSpace)
    {
        return toAjax(parkSpaceService.updateParkSpace(parkSpace));
    }

    /**
     * 删除车位管理
     */
    @PreAuthorize("@ss.hasPermi('park:space:remove')")
    @Log(title = "车位管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{spaceIds}")
    public AjaxResult remove(@PathVariable Long[] spaceIds)
    {
        return toAjax(parkSpaceService.deleteParkSpaceBySpaceIds(spaceIds));
    }

    private class Park {
    }
}
